﻿using DotNetExtensions.AspNet.Http;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AspNetSimple
{
    public class HttpClientSimple
    {
        public HttpClientSimple()
        {
            #region HttpClient Simple

            var client = new RestfulHttpRequest();

            //string data = "{\"DeviceId\":0,\"DeviceType\":null,\"SN\":\"8152520120001794\",\"PersonCode\":\"888\",\"PersonName\":\"大哥\",\"CheckinTime\":\"2022 - 03 - 23T17: 26:55\",\"CheckinPhotoPath\":\"2022\\3\\23\\000001.jpg\",\"Id\":0,\"CreateTime\":\"2022 - 03 - 23T18: 15:42.1491272 + 08:00\",\"LastUpdateTime\":null,\"CreateUserId\":1,\"LastUpdateUserId\":0,\"CreateUserName\":null,\"LastUpdateUserName\":null}";
            //var resp = client.Post("http://localhost:7447/api/CheckRecord/add2", Encoding.UTF8.GetBytes(data), null);

            HttpRequest request = new HttpRequest();
            request.Content = Encoding.UTF8.GetBytes("{\"data\":\"eyJEb2NObyI6IklOVk9LRSIsIkRvY1R5cGUiOjAsIkl0ZW1Db2RlIjoiSU5WT0tFIiwiQXJyaXZlUXR5IjowLjAsIkRlbGl2ZXJ5UXR5IjowLjAsIkFycml2ZURhdGUiOiIiLCJMaW5lTm8iOjAsIlN0b2NrUXR5IjowLjAsIlN0b2NrVGltZSI6IiIsIlN0b2NrV2hDb2RlIjoiIiwiUXVhbGlmaWVkUXR5IjowLjAsIlVuUXVhbGlmaWVkUXR5IjowLjAsIlFDVGltZSI6IiIsIkNvbmNlc3Npb25RdHkiOjAuMH0 = \",\"context\":{\"CultureName\":\"zh - CN\",\"OrgCode\":\"211\",\"UserCode\":\"WMS接口\",\"EntCode\":\"01\"}}");
            request.Headers.Add(new Header("Content-Type", "application/json"));
            var resp = client.Send("http://10.0.0.128/U9/RestServices/UFIDA.CUST.VW.ARRIVAL.WRITEBACKSV.IArrived.svc/do", request, Method.POST);

            Console.WriteLine(resp);

            //var reponse = client.Get("http://192.168.10.27:5000/api/person/find?key=22022801");
            //if (reponse.OK)
            //{
            //    Console.WriteLine(reponse.GetString());
            //}

            //var client2 = HttpClientFactory.Default.Create(HttpClientFactory.HttpClientKind.File);

            //var reponse2 = client2.Get("http://192.168.20.217/7z1900-x64.exe");
            //if (reponse2.OK)
            //{
            //    bool save = reponse2.Save("d:\\7z1900-x64.exe");

            //    Console.WriteLine("Download File Saved = {0}", save);
            //}
            //else
            //{
            //    Console.WriteLine("Error:{0}", reponse2.GetString());
            //}

            //client2.GetAsync("http://192.168.20.217/cn_windows_7_professional_x64_dvd_x15-65791.iso");
            //client2.Progress += (url, e) =>
            //{
            //    var fileArgs = e as FileTransferArgs;
            //    Console.WriteLine("Progress:{0}%", fileArgs.Progress * 100);
            //};
            //client2.Completed += (url, e) =>
            //{
            //    var fileArgs = e as FileTransferArgs;
            //    Console.WriteLine("Download Completed");
            //    //if (fileArgs.Successed)
            //    //{
            //    //    System.IO.File.Move(fileArgs.FileName, "d:\\cn_windows_7_professional_x64_dvd_x15-65791.iso");
            //    //    Console.WriteLine("File Move to D:\\");
            //    //}
            //};

            //HttpClientFactory.Default.GetAsync(new string[] { "http://192.168.20.217/7z1900-x64.exe", "http://192.168.20.217/git-2.33.1-64-bit.exe" }, progress =>
            //{
            //    Console.WriteLine("Progress:{0}", progress * 100);
            //},
            //files =>
            //{
            //    Console.WriteLine("Download Completed:{0}", string.Join(",", files));
            //});

            #endregion
        }
    }
}
